<%@ include file="/inc/header.jsp" %>

<script language="JavaScript">
<!--
	function updateMainCategoryList(categoryId, mainCategoryId)
	{
		if (mainCategory == undefined)
			return ;
		if (categoryId.checked)
		{
			mainCategoryId.options[mainCategoryId.options.length] = new Option(
				categoryList[categoryId.value],
				categoryId.value
			);
		}
		else
		{
			for (i = 0; i < mainCategoryId.options.length; i++)
			{
				if (mainCategoryId.options[i].value == categoryId.value)
				{
					mainCategoryId.remove(i);
					break;
				}
			}
		}
	}
	
	var categoryList = new Array();
	<logic:present name="categorylist">
	  	<logic:iterate id="categoryForm" name="categorylist">
		categoryList[<bean:write name="categoryForm" property="id" />] = '<bean:write name="categoryForm" property="fullname" />';
		</logic:iterate>
	</logic:present>

//-->
</script>


<html:form action="/massiveadd.do">
<html:hidden property="type" />
<html:hidden property="elementcount" />
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="4">
  <tr align="center" bgcolor="#3366CC">
    <td colspan="4"><font color="white"><b>Ajout de <yacme:type name="multiElementForm" property="type" /></b></font></td>
  </tr>
  <tr>
    <td width="4%">&nbsp;</td>
    <td width="32%">&nbsp;</td>
    <td width="32%">&nbsp;</td>
    <td width="32%">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="4">&nbsp;</td>
  </tr>
  	<bean:define id="elementcount" name="multiElementForm" property="elementcount" />
<%
	int numElement = ((Integer) elementcount).intValue();
	for (int i = 0; i < numElement; i++)
	{
%>
  <tr valign="top">
    <td><input type="checkbox" name="chosen<%= i %>" value="true" /></td>
	<logic:equal name="multiElementForm" property="type" value="L">
	    <td valign="top" colspan="3"><strong>Lien : &nbsp;</strong><br><input type="text" name="url<%= i %>" size="150" /></td>
	  </tr>
	  <tr valign="top">
	    <td>&nbsp;</td>
	</logic:equal>
	<logic:equal name="multiElementForm" property="type" value="F">
	    <td valign="top" colspan="3"><strong>Fichier : &nbsp;</strong><br><input type="file" name="filename<%= i %>" size="150" /></td>
	  </tr>
	  <tr valign="top">
	    <td>&nbsp;</td>
	</logic:equal>
    <td valign="top">
    	<strong>Titre : &nbsp;</strong><br>
    	<input type="text" name="title<%= i %>" size="60" />
    </td>
    <td valign="top" colspan="2">
    	<strong>Description : &nbsp;</strong><br>
    	<input type="text" name="description<%= i %>" size="60" />
    </td>
  </tr>
  <tr valign="top">
    <td valign="top">&nbsp;</td>
    <td valign="top" rowspan="2">
    	<strong>Mots-cl&eacute;s</strong><br>
		<select name="keywordIds<%= i %>" size="30" multiple="true" class="keywords">
			<logic:iterate id="keyword" name="keywordlist">
			<option value="<bean:write name="keyword" property="id" />"><bean:write name="keyword" property="name" /></option>
			</logic:iterate>
	    </select>
	</td>
    <td valign="top" align="left">
      	<%
      		int size = ((java.util.List) request.getAttribute("categorylist")).size();
      		int count = (size+1) / 2;
      		String countStr = String.valueOf(count);
      	%>
      	<logic:iterate id="categoryForm" indexId="numCat" name="categorylist">
			<logic:equal name="numCat" value="<%= countStr %>">
			  </td>
		      <td align="left" valign="top">
			</logic:equal>
			<bean:define id="categoryId" name="categoryForm" property="id" />
			<input type="checkbox" name="categoryIds<%= i %>" value="<%= categoryId.toString() %>" onclick="updateMainCategoryList(this, document.multiElementForm.mainCategoryId<%= i %>)" />&nbsp;
			<bean:write name="categoryForm" property="fullname" /><br>
		</logic:iterate>
    </td>
    <td valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top">&nbsp;</td>
    <td valign="top" colspan="3">
	<logic:equal name="multiElementForm" property="type" value="F">
    	<b>Rangez dans :</b><br>
    	<select name="mainCategoryId<%= i %>" class="maincategory">
		</select>
	</logic:equal>
    </td>
  </tr>
  <tr>
    <td colspan="4" valign="top"><hr></td>
  </tr>
  <tr>
    <td colspan="4">&nbsp;</td>
  </tr>
<%
	}
%>
  <tr>
    <td colspan="4" align="center">
    	<html:hidden property="actionName" value="MassiveAdd" />
    	<html:submit property="foo" value="Ajouter les documents" styleClass="button" />
    </td>
  </tr>
  <tr>
    <td colspan="4">&nbsp;</td>
  </tr>
</table>
</html:form>

<%@ include file="/inc/footer.jsp" %>
